package com.share.jdbc.controller;

import com.share.jdbc.dao.OrderDao;
import com.share.jdbc.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
public class TestController {

    @Autowired
    private OrderDao orderDao;


    @GetMapping("/test")
    public String test(){
        List<Order> list = getList();
        long starttime = System.currentTimeMillis();
//        int i = orderDao.insertList(list);
        int i = 1;
        String res = "消耗时间：" + (System.currentTimeMillis() - starttime)/1000 + " 秒";
        System.out.println(res);
        if (i > 0){
            return "test - ok，" + res;
        }
        return "error";
    }

    private List<Order> getList() {
        List<Order> list = new ArrayList<>();
        Date date = new Date();
        for (int i = 0; i < 1000; i++) {
            //list.add(Order.builder().id((long)i).name("小二" + i).type(i+"").gmtCreate(date).build());
            //list.add(Order.builder().name("小二" + i).type(i+"").gmtCreate(date).build());
            // 使用 shading 自带的 SNOWFLAKE 算法生成主键
            orderDao.insertSelective(Order.builder().name("小二" + i).type(i+"").gmtCreate(date).build());
        }
        return list;
    }
}
